__author__ = 'Administrator'


# global语句可以用来指明某个特定的表明位于全局作用域并且应该在那里重新绑定；
# nonlocal语句表示特定的变量位于一个封闭的作用域并且应该在那里重新绑定。

def scope_test():
    def do_local():
        spam = "local spam"

    def do_nonlocal():
        nonlocal spam
        spam = "nonlocal spam"

    def do_global():
        global spam
        spam = "global spam"

    spam = "test spam"
    do_local()
    print("After local assignment:", spam)
    do_nonlocal()
    print("After nonlocal assignment:", spam)
    do_global()
    print("After global assignment:", spam)


scope_test()
print("In global scope:", spam)
